﻿namespace WinnerCMS.BLL
{
    #region 命名空间

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Common;
    using Data;
    using Model;

    #endregion

    public class UnitManage
    {
        private static readonly UnitDal MyDAL = new UnitDal();

        public void Add(WinnerCMS.Model.Unit model, ref string strErr)
        {
            if (model.Name.Length == 0)
            {
                strErr = "“单位”不能为空！";
            }
            else if (model.Id == 0)
            {
                MyDAL.Add(model);
            }
            else
            {
                MyDAL.Edit(model);
            }
        }

        public void BindList(Repeater R_Unit)
        {
            R_Unit.DataSource = MyDAL.BindList();
            R_Unit.DataBind();
        }

        /// <summary>
        /// 绑定分页数据
        /// </summary>
        /// <param name="pp"></param>
        /// <returns></returns>
        public IList<WinnerCMS.Model.Unit> BindList(PagingParam pp)
        {
            return MyDAL.BindList(pp);
        }

        public void Delete(string IDs, UpdatePanel UpdatePanel1)
        {
            if (string.IsNullOrEmpty(IDs))
            {
                MsgBox.Message("至少选择一项。", UpdatePanel1);
            }
            else
            {
                int[] ids = (from x in IDs.Split(',') select int.Parse(x)).ToArray();
                MyDAL.Delete(ids);
            }
        }

        public WinnerCMS.Model.Unit GetInfo(int ID)
        {
            return MyDAL.GetInfo(ID);
        }
    }
}